<?php

/**
 * This is the model class for table "shop".
 *
 * The followings are the available columns in table 'shop':
 * @property integer $id
 * @property integer $id_category_theme
 * @property string $name_shop
 * @property string $address
 * @property string $first_name
 * @property string $last_name
 * @property string $email
 * @property string $city
 * @property string $phone
 * @property string $domain
 * @property string $pass
 * @property integer $is_shop
 * @property string $district
 * @property string $description
 */
class Shop extends PIActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'shop';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_category_theme, name_shop, address, first_name, last_name, email, city, phone, domain, pass, is_shop, district', 'required'),
			array('id_category_theme, is_shop', 'numerical', 'integerOnly'=>true),
			array('name_shop, address, first_name, last_name, email, city, domain, pass, district', 'length', 'max'=>255),
			array('phone', 'length', 'max'=>30),
			array('domain','unique', 'message'=>'{attribute} đã tồn tại'),
			array('description', 'length', 'max'=>500),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_category_theme, name_shop, address, first_name, last_name, email, city, phone, domain, pass, is_shop, district, description', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'categories' => array(self::BELONGS_TO, 'CategoriesTheme', 'id_category_theme'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_category_theme' => 'Tên lĩnh vực',
			'name_shop' => 'Tên của hàng',
			'address' => 'Địa chỉ',
			'first_name' => 'Họ đệm',
			'last_name' => 'Tên',
			'email' => 'Email',
			'city' => 'Tỉnh/Thành phố',
			'phone' => 'Điện thoại',
			'domain' => 'Tên website',
			'pass' => 'Mật khẩu',
			'is_shop' => 'Is Shop',
			'district' => 'Quận/Huyện',
			'description' => 'Mô tả',
			'created' => 'Ngày đăng ký',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('id_category_theme',$this->id_category_theme);
		$criteria->compare('name_shop',$this->name_shop,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('domain',$this->domain,true);
		$criteria->compare('pass',$this->pass,true);
		$criteria->compare('is_shop',$this->is_shop);
		$criteria->compare('district',$this->district,true);
		$criteria->compare('description',$this->description,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Shop the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
